﻿

function lienKetYahoo() {
    if ($('#taiKhoanLienKets').find('#tkLienKet-Yahoo').length > 0) {
        alert('Đã liên kết với Yahoo!Messenger');
        return;
    }
    var div = '<div id="tkLienKet-Yahoo">' +
                '<div style="width:270px;height:40px">' +
                    '<img alt="..." src="http://l.yimg.com/a/i/us/msg/site/9/el/header/yahoo_msg_logo_vn_2.png"' +
                        'width="195" height="30" style="background:rgb(102, 44, 146)" />' +
                '</div>' +
            '</div>';
    $('#taiKhoanLienKets').append(div);
    disablePopup('#dlgTKLienKet');
}

function lienKetFacebook() {
    if ($('#taiKhoanLienKets').find('#tkLienKet-Facebook').length > 0) {
        alert('Đã liên kết với Facebook');
        return;
    }
    var div = '<div id="tkLienKet-Facebook">' +
                '<div style="width:270px;height:37px">' +
                    '<img alt="..." src="https://fbstatic-a.akamaihd.net/rsrc.php/v2/yS/x/B1l0pVYCp2E.png"' +
                        'width="195" height="30" style="background:#44f" />' +
                '</div>' +
            '</div>';
    $('#taiKhoanLienKets').append(div);
    disablePopup('#dlgTKLienKet');
}


var popupStatus = 0;
var formPopup = "";


function loadPopup(popup) {
    if (popupStatus == 0) {
        centerPopup(popup);
        $("#overlay").css({
            "opacity": "0.7"
        });
        $("#overlay").fadeIn("slow");
        $(popup).fadeIn("slow");
        popupStatus = 1;
        formPopup = popup;
    }
}

function disablePopup(popup) {
    if (popupStatus == 1) {
        $(popup).fadeOut("slow");
        $('#overlay').fadeOut("slow");
        popupStatus = 0;
        formPopup = "";
    }
}

function centerPopup(popup) {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(popup).height();
    var popupWidth = $(popup).width();

    $(popup).css({
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });

    $("#overlay").css({
        "height": windowHeight
    });
}

$(document).ready(function () {

    $('#overlay').click(function () {
        disablePopup(formPopup);
    });

    $('.bnClose').click(function () {
        disablePopup(formPopup);
    });

    $('#bnLienKetTaiKhoan').click(function () {
        loadPopup('#dlgTKLienKet');
    });

    $('#bnLKFacebook').click(function () {
        lienKetFacebook();
    });

    $('#bnLKYahoo').click(function () {
        lienKetYahoo();
    });
});